<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateConfigTable extends Migrator
{
    /**
     * Migrate Up.
     */
    public function up()
    {
        $table = $this->table('config', ['id' => false, 'primary_key' => 'code', 'comment' => '系统配置', 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci']);
        $table->addColumn('code', 'string', ['limit'  =>  100, 'null' => false, 'comment' => '配置标识'])
            ->addColumn('parent_code', 'string', ['limit'  =>  60, 'null' => true, 'default' => null, 'comment' => '上级标识'])
            ->addColumn('name', 'string', ['limit'  =>  60, 'default' => '', 'comment' => '配置名称'])
            ->addColumn('description', 'string', ['limit'  =>  255, 'null' => true, 'default' => null, 'comment' => '描述'])
            ->addColumn('type', 'string', ['limit'  =>  60, 'null' => true, 'default' => null, 'comment' => '类型:group,string,text,int,radio,select,select_mult,bool,array,datetime,date,file'])
            ->addColumn('value', 'string', ['limit'  =>  512, 'null' => true, 'default' => null, 'comment' => '配置内容'])
            ->addColumn('store_range', 'string', ['limit'  => 512, 'null' => true, 'default' => null, 'comment' => '配置选项'])
            ->addColumn('rule', 'string', ['limit'  =>  60, 'null' => true, 'default' => null, 'comment' => '验证规则'])
            ->addColumn('weigh', 'integer', ['limit'  =>  8, 'default' => 50, 'comment' => '权重'])
            ->create();
    }

    /**
     * Migrate Down.
     */
    public function down()
    {
        $table = $this->table('config');
        $table->drop();
    }
}
